angular.module("driver").controller("AdminApplysCtrl", ['$scope', '$meteor', '$rootScope', '$state', '$ionicPopup', 'Map',
  function($scope, $meteor, $rootScope, $state, $ionicPopup, Map){

    $meteor.subscribe('applys').then(function(subscriptionHandle){
      $scope.applys = $meteor.collection(Applys);
    });

    $scope.reject = function (apply) {
      $scope.data = apply;
      // An elaborate, custom popup
      var myPopup = $ionicPopup.show({
        //template: '<input type="password" ng-model="data.wifi">',
        template: '<input type="text" ng-model="data.reason">',
        title: '反馈',
        subTitle: '输入不通过原因',

        scope: $scope,
        buttons: [
          { text: 'Cancel' },
          {
            text: '确定',
            onTap: function(e) {
              return $scope.data;
            }
          }
        ]
      });
      myPopup.then(function(res) {
        if (!res) return;
        res.pass = true;
        Messages.insert({userid: res.userid, msg: res.reason, read: false});
      });
    }
    $scope.pass = function (apply) {
      apply.pass = true;
      Messages.insert({userid: apply.userid, msg: '代驾资格审核通过', read: false});
      Meteor.call('updateRole', apply.userid, 'driver');
    }

    $scope.detail = function(apply) {
      $scope.data = apply;
      // An elaborate, custom popup
      var myPopup = $ionicPopup.show({
        //template: '<input type="password" ng-model="data.wifi">',
        template: '<ion-content>\
                    <div class="list">\
                    <div class="item item-image">\
                      <img ng-src={{data.images.face}}>\
                    </div>\
                    <div class="item item-image">\
                      <img ng-src={{data.images.driving_license}}>\
                    </div>\
                    <div class="item item-image">\
                      <img ng-src={{data.images.identity_card}}>\
                    </div>\
                    <a class="item item-icon-left item-icon-right">\
                      <i class="icon ion-android-person"></i>\
                      {{data.info.realname}}\
                      <i></i>\
                    <a class="item item-icon-left item-icon-right">\
                      <i class="icon ion-ios-telephone-outline"></i>\
                      {{data.info.tel}}\
                      <i></i>\
                    </div>\
                    </ion-content>',

        template: '<i>向右滑动显示更多图片</i>\
<ion-slide-box on-slide-changed="slideHasChanged($index)">\
  <ion-slide>\
    <img class="full-image" ng-src={{data.images.face}}>\
  </ion-slide>\
  <ion-slide>\
    <img class="full-image" ng-src={{data.images.driving_license}}>\
  </ion-slide>\
  <ion-slide>\
    <img class="full-image" ng-src={{data.images.identity_card}}>\
  </ion-slide>\
</ion-slide-box>',

        title: apply.info.realname,
        subTitle: apply.info.tel,
        scope: $scope,
        buttons: [
          { 
            text: '取消' ,
            type: 'button-assertive',},
            
          {
            text: '通过',
            type: 'button-royal',
            //type: 'ion-ios-telephone-outline',
            //hide: !info.tel,
            onTap: function(e) {
              return $scope.data;
            }
          }
        ]
      });
      myPopup.then(function(res) {
        if (!res) return;
        res.pass = true;
        Messages.insert({userid: res.userid, msg: '代驾资格审核通过', read: false});
        Meteor.call('updateRole', res.userid, 'driver');
      });
    };

}]);
